<!DOCTYPE HTML>
<html>
<head>
    <title>登录</title>
    <!-- Custom Theme files -->
    <link href="__STATIC__/css/pub-login-style.css" rel="stylesheet" type="text/css" media="all"/>
    <!-- Custom Theme files -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="Login form web template, Sign up Web Templates, Flat Web Templates, Login signup Responsive web template, Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
</head>
<body>
<div class="login">
    <h2>欢迎使用线上图书馆</h2>
    <div class="login-top">
        <h1>登录图书馆</h1>
        <form name="login-form">
            <input type="text" name="user_name" value="" placeholder="请输入账号">
            <input type="password" name="user_pwd" value="" placeholder="请输入密码">
            <label style="float: left;margin: 8px"><input type="checkbox" name="remember"> 记住登录</label>
        </form>
        <div class="forgot">

            <a href="#">找回密码</a>
            <input type="submit" value="登录">
        </div>
        <div class="error-message" style="display: none">
            账号密码错误
        </div>
    </div>
    <div class="login-bottom">
        <h3>新用户请 &nbsp;<a href="/pub/register">注册</a>&nbsp;账号</h3>
    </div>
</div>
<script src="__STATIC__/js/jquery.min.js"></script>
<script>
    var countdown = 3;
    function showErrorMsg(msg) {
        if (countdown===0) {
            $('.error-message').hide();
            countdown = 3;
            return false;
        }else {
            $('.error-message').html(msg+'<span style="float: right">'+countdown+'</span>').show();
            countdown--;
        }
        setTimeout(function () {
            showErrorMsg(msg);
        }, 1000);
    }
    $('input[type="submit"]').click(function () {
        var form_data=$('form[name="login-form"]').serialize();
        $.ajax({
            type:'post',
            url:"/pub/login/index",
            dataType:'json',
            data:form_data,
            success:function (obj) {
                if (obj.code<1) {
                    showErrorMsg(obj.msg);
                    return false;
                }
                var url = document.referrer;
                if (url.search('/register')!=-1 || url.search('/login')!=-1 ) {
                    window.location.replace('/index');
                } else {
                    window.location.replace(document.referrer);
                }

            }
        });
    });
</script>

</body>
</html>